<?php

namespace App\Http\Controllers\Api;

use App\Constants\CodeResponse;
use App\Http\Requests\BrandDetailRequest;
use App\Http\Requests\BrandListRequest;
use App\Services\BrandService;
use Illuminate\Http\JsonResponse;

class BrandController extends ApiController
{
    public function list(BrandListRequest $request): JsonResponse
    {
        $page = $request->post('page', 1);
        $pageSize = $request->post('pageSize', 10);
        $sort = $request->post('sort','created_at');
        $order = $request->post('order', 'desc');

        $columns = ['id', 'name', 'desc', 'pic_url', 'floor_price'];
        $list = BrandService::getInstance()->getList($page, $pageSize, $sort, $order, $columns);
        $list = $this->successPaginate($list);
        return $this->success($list);
    }

    public function detail(BrandDetailRequest $request): JsonResponse
    {
        $id = $request->post('id');
        $info = BrandService::getInstance()->getById($id);
        if (is_null($info)) {
            return $this->fail(CodeResponse::PARAM_VALUE_ILLEGAL);
        }
        return $this->success($info);
    }
}